﻿#include "timer_driver.h"
#include "lv_hal_tick.h"
#include "sb_gateway.h"

void timer2_init(void)
{
	timer_parameter_struct timer_initpara;
	rcu_periph_clock_enable(RCU_TIMER2);
	timer_deinit(TIMER2);
	/* initialize TIMER init parameter struct */
	timer_struct_para_init(&timer_initpara);
	/* TIMER1 configuration */
	timer_initpara.prescaler = 1079;
	timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
	timer_initpara.counterdirection = TIMER_COUNTER_UP;
	timer_initpara.period = 99;
	timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
	timer_init(TIMER2, &timer_initpara);

	timer_interrupt_flag_clear(TIMER2, TIMER_INT_FLAG_UP);
	timer_interrupt_enable(TIMER2, TIMER_INT_UP);
	timer_enable(TIMER2);
}


void timer2_int_disable(void)
{
	
	timer_interrupt_disable(TIMER2, TIMER_INT_UP);
	timer_interrupt_flag_clear(TIMER2, TIMER_INT_FLAG_UP);
}

void timer2_int_enable(void)
{
	
	timer_interrupt_enable(TIMER2, TIMER_INT_UP);
	timer_interrupt_flag_clear(TIMER2, TIMER_INT_FLAG_UP);

}



void TIMER2_IRQHandler(void)
{
	if (SET == timer_interrupt_flag_get(TIMER2, TIMER_INT_FLAG_UP))
	{
		time_task_get_tick_1ms();
		lv_tick_inc(1);
		level_alarm_ctr_1ms_tick();
		netway_timer_handle();
		timer_interrupt_flag_clear(TIMER2, TIMER_INT_FLAG_UP);
	}
}
